package com.qzy.sort;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

/**
 * @描述
 * @创建人 joy_qiu
 * @创建时间 2019-12-23-10:30
 * @修改人和其它信息
 */
public class BubbleSort {
    public static void main(String[] args) {
        int [] a = {9,3,5,2,6,0};
        System.out.println("sort1 0---->n");
        long start = System.currentTimeMillis();
        for (int i = 0; i < a.length ; i++) {
            for (int j = i+1; j < a.length; j++) {
                if(a[i]>a[j]){
                    int b = a[j];
                    a[j]=a[i];
                    a[i]=b;
                }
            }
        }
        System.out.println("排序耗时："+(System.currentTimeMillis() - start));
        System.out.println("<<<<<<<<<<<<<<<<<<<<排序后>>>>>>>>>>>>>>>>>>>>>>");
        printIntArray(a);

        System.out.println("sort2 n---->0");
        long start2 = System.currentTimeMillis();
        for (int i = 0; i < a.length ; i++) {
            for (int j = i+1; j < a.length ; j++) {
                if(a[i] < a[j]){
                    int b = a[j];
                    a[j] = a[i];
                    a[i] = b;
                }
            }
        }
        System.out.println("排序耗时："+(System.currentTimeMillis() - start2));
        System.out.println("<<<<<<<<<<<<<<<<<<<<排序后>>>>>>>>>>>>>>>>>>>>>>");
        printIntArray(a);


        List<Integer> list =  new ArrayList<>();
        list.add(5);
        list.add(3);
        list.add(12);
        list.add(114);
        list.add(10);
        list.add(10);
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });
        System.out.println("list.sort排序后");
        Iterator<Integer> integerIterator = list.iterator();
        while(integerIterator.hasNext()){
            System.out.println(integerIterator.next());
        }
    }


    public static void printIntArray(int [] array){
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

}
